package com.kcyu.egoodsmapbackend.enums;

import cn.hutool.json.JSON;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONString;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.annotation.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.Getter;

import java.util.HashMap;

@Getter
public enum PresaleEnums implements IEnum<String> {

    CURRENT("CURRENT", "现货"),
    PRESALE("PRESALE", "预售");

    private final String value;
    private final String desc;

    @JsonValue
    private final String display;

    PresaleEnums(String value, String desc) {
        this.value = value;
        this.desc = desc;
        HashMap<String, String> map = new HashMap<>();
        map.put("dictParam", value);
        map.put("displayName", desc);
        // 序列化map
        this.display = JSONUtil.toJsonPrettyStr(map);
    }

    @JsonCreator
    public static PresaleEnums getByValue(String value) {
        for (PresaleEnums presaleEnums : PresaleEnums.values()) {
            if (presaleEnums.getValue().equals(value)) {
                return presaleEnums;
            }
        }
        return null;
    }

    @Override
    public String getValue() {
        return this.value;
    }
}
